<template>
	<view class="page">
		<fu-custom :isBack="true" :isBottom="true" bgColor="bg-white">
			<block slot="content"><text class="text-333 text-xl">添加商品</text></block>
			<!-- <block slot="right"><text class="text-theme text-df" @click="previewGoods">预览</text></block> -->
		</fu-custom>
		<!-- 商品添加 -->
		<view class="addGoods-wrap padding-bottom">

			<view class="addGoods-item solid-bottom padding-tb">
				<view class="addGoods-title text-333 text-lg flex justify-between align-center">
					<text>
						<text class="text-lg text-333">商品封面图片</text>
						<text class="text-sm text-999">(请上传尺寸为400*400像素的图片)</text>
					</text>
					<text class="text-sm text-999">{{ goods_info.thumb ? 1 : 0 }}/1</text>
				</view>

				<view class="addGoods-content margin-top-16">
					<view class="image-wrap flex flex-wrap">
						<view class="goods-img" v-if="thumb_img">
							<image class="img" :src="thumb_img" mode="aspectFill"></image>
							<image src="/static/management/close.png" class="close" mode="widthFix"
								@click="clearImg('thumb', goods_info.thumb)" />
						</view>
						<image v-if="!goods_info.thumb" class="add-img" src="/static/management/add.png" mode="widthFix"
							@click="upLoadImg(1, 'thumb')"></image>
					</view>
				</view>
			</view>
			<view class="addGoods-item solid-bottom padding-tb">
				<view class="addGoods-title text-333 text-lg flex justify-between align-center">
					<text>
						<text class="text-lg text-333">商品图片</text>
						<!-- <text class="text-sm text-999">(请上传尺寸为400*400像素的图片)</text> -->
					</text>
					<text class="text-sm text-999">{{ img_list.length }}/{{ max }}</text>
				</view>
				<view class="addGoods-content margin-top-16">
					<view class="image-wrap flex flex-wrap">
						<view class="goods-img" v-for="(item, index) in img_list" :key="index">
							<image class="img" :src="item.path" mode="aspectFill"></image>
							<image src="/static/management/close.png" class="close" mode="widthFix"
								@click="clearImg('img_list', item.id)" />
						</view>
						<image v-if="img_list.length < max" class="add-img" src="/static/management/add.png"
							mode="widthFix" @click="upLoadImg(9, 'img_list', max)"></image>
					</view>
				</view>
			</view>
			<view class="addGoods-item solid-bottom padding-tb">
				<view class="addGoods-title text-333 text-lg flex justify-between align-center">
					<text><text class="text-lg text-333">商品视频</text></text>
					<text class="text-sm text-999">{{ goods_info.video ? 1 : 0 }}/1</text>
				</view>
				<view class="addGoods-content margin-top-16">
					<view class="image-wrap flex flex-wrap">
						<view class="goods-img" v-if="goods_info.video">
							<!-- <image class="img" :src="videoInfo.videoPoster" mode="aspectFill"></image> -->
							<video class="img" :src="videoInfo.file" ></video>
							<image src="/static/management/close.png" class="close" mode="widthFix" style="z-index: 999;"
								@click="clearVideo" />
						</view>
						<image v-if="!goods_info.video" class="add-img" src="/static/management/add.png" mode="widthFix"
							@click="addVideo"></image>
					</view>
				</view>
			</view>
			<!-- <view class="addGoods-item solid-bottom padding-tb">
				<view class="addGoods-title text-333 text-lg">名称 *</view>
				<view class="addGoods-content margin-top-16">
					<textarea
						name=""
						v-model="goods_info.name"
						class="textarea-title"
						id=""
						placeholder="请输入商品标题，如商品品牌+名字等"
						placeholder-class="placeholder"
						maxlength="200"
					></textarea>
				</view>
			</view> -->

			<view class="addGoods-item solid-bottom padding-tb flex justify-between">
				<view class="text-df _left">商品信息</view>
			</view>
			<view class="addGoods-item solid-bottom padding-tb flex justify-between">
				<view class="text-df _left">名称</view>
				<view class="text-right _right"><input v-model="goods_info.name" type="text" placeholder="请输入（2~30个字符）"
						placeholder-class="placeholder" /></view>
			</view>


           <view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
            	<view class="text-333 text-df _left">市场价</view>
            	<view class="text-right _right"><input type="number" placeholder="进价金额仅自己可见"
            			placeholder-class="placeholder" v-model="goods_info.market_price" />
            			<text class="right_type">元</text></view>
            </view>
			<!-- <view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
				<view class="text-333 text-df _left">会员价</view>
				<view class="text-right _right"><input type="number" placeholder="进价金额仅自己可见"
						placeholder-class="placeholder" v-model="goods_info.member_price" />
						<text class="right_type">元</text></view>
			</view> -->
			<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
				<view class="text-333 text-df _left">价格</view>
				<view class="text-right _right">
					<input type="number" placeholder="请输入价格" placeholder-class="placeholder"
						v-model="goods_info.shop_price" />
						
						<text class="right_type">元</text>
				</view>
			</view>

			<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
				<view class="text-333 text-df _left">进价</view>
				<view class="text-right _right"><input type="number" placeholder="进价金额仅自己可见"
						placeholder-class="placeholder" v-model="goods_info.cost_price" />
						<text class="right_type">元</text></view>
			</view>
			<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
				<view class="text-333 text-df _left">库存</view>
				<view class="text-right _right"><input type="number" placeholder="请输入库存" placeholder-class="placeholder"
						v-model="goods_info.stock" /></view>
			</view>
			<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
				@click="openPicker('shopCate')">
				<view class="text-333 text-df _left">商城分类</view>
				<view class="_right">
					<text class="text-df text-333">{{ shopValue ? shopValue : '请选择' }}</text>
					<text class="cuIcon-right text-999 margin-left-sm"></text>
				</view>
			</view>
			<!-- 马匹用途 -->
			<view v-if="false">
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('linkage')">
					<view class="text-333 text-df _left">马匹用途</view>
					<view class="_right">
						<text class="text-df text-333">{{ categoryVal.name ? categoryVal.name : '请选择' }}</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('selector')">
					<view class="text-333 text-df _left">品种</view>
					<view class="_right">
						<text class="text-df text-333">{{ brandVal.name ? brandVal.name : '请选择' }}</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('sex')">
					<view class="text-333 text-df _left">性别</view>
					<view class="_right">
						<!-- 	<view class="text-right _right"><input type="text" placeholder="请输入性别"
								placeholder-class="placeholder" v-model="goods_info.sex" /></view> -->
						<view class="_right">
							<text class="text-df text-333">{{ sexVal ? sexVal: '请选择' }}</text>
							<text class="cuIcon-right text-999 margin-left-sm"></text>
						</view>
					</view>
				</view>
				<view v-if="goods_type != 1" class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('purpose')">
					<view class="text-333 text-df _left">用途</view>
					<view class="_right">
						<!-- <view class="text-right _right"><input type="text" placeholder="请输入用途"
								placeholder-class="placeholder" v-model="goods_info.used" /></view> -->
						<view class="_right">
							<text class="text-df text-333">{{ purposeVal ? purposeVal: '请选择' }}</text>
							<text class="cuIcon-right text-999 margin-left-sm"></text>
						</view>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('color')">
					<view class="text-333 text-df _left">颜色</view>
					<view class="_right">
						<text class="text-df text-333">{{ colorVal ? colorVal: '请选择' }}</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
					<view class="text-333 text-df _left">年龄</view>
					<view class="_right">
						<!-- 生日  年龄 年龄 @click="openPicker('time')"-->
						<view class="text-right _right" >
							<input type="number" placeholder="请输入年龄"
								placeholder-class="placeholder" v-model="goods_info.birthday" />
								<text class="right_type">岁</text>
							<!-- 	<text class="text-df text-333">{{ dateTime ? dateTime: '请选择' }}</text>
								<text class="cuIcon-right text-999 margin-left-sm"></text> -->
						</view>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
					<view class="text-333 text-df _left">身高</view>
					<view class="_right">
						<view class="text-right _right"><input type="text" placeholder="请输入身高"
								placeholder-class="placeholder" v-model="goods_info.height" />
								<text class="right_type">cm</text>
							</view>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
					<view class="text-333 text-df _left">体重</view>
					<view class="_right">
						<view class="text-right _right"><input type="text" placeholder="请输入体重"
								placeholder-class="placeholder" v-model="goods_info.weight_body" />
								<text class="right_type">kg</text>
								</view>
					</view>
				</view>
			</view>
			<!-- 马粮分类 -->
			<view v-if="false">
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('linkage')">
					<view class="text-333 text-df _left">马粮分类</view>
					<view class="_right">
						<text class="text-df text-333">{{ categoryVal.name ? categoryVal.name : '请选择' }}</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('selector')">
					<view class="text-333 text-df _left">品牌</view>
					<view class="_right">
						<text class="text-df text-333">{{ brandVal.name ? brandVal.name : '请选择' }}</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
					<view class="text-333 text-df _left">产地</view>
					<view class="_right">
						<view class="text-right _right"><input type="text" placeholder="请输入产地"
								placeholder-class="placeholder" v-model="goods_info.producing_area" /></view>
					</view>
				</view>
				<!-- <view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
					<view class="text-333 text-df _left">规格描述</view>
					<view class="_right">
						<view class="text-right _right"><input type="text" placeholder="请输入规格描述"
								placeholder-class="placeholder" v-model="goods_info.item" /></view>
					</view>
				</view> -->
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
					<view class="text-333 text-df _left">适用对象</view>
					<view class="_right">
						<view class="text-right _right"><input type="text" placeholder="请输入适用对象"
								placeholder-class="placeholder" v-model="goods_info.suit" /></view>
					</view>
				</view>

			</view>
			<!-- 马具分类 -->
			<view v-if="false">
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('linkage')">
					<view class="text-333 text-df _left">马具分类</view>
					<view class="_right">
						<text class="text-df text-333">{{ categoryVal.name ? categoryVal.name : '请选择' }}</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				
				<!-- 待添加类型 -->
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('types')">
					<view class="text-333 text-df _left">马具类型</view>
					<!-- <view class="_right">
						<view class="text-right _right"><input type="text" placeholder="请输入颜色"
								placeholder-class="placeholder" v-model="goods_info.colour" /></view>
					</view> -->
					<view class="_right">
						<text class="text-df text-333">{{ typesVal ? typesVal: '请选择' }}</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				<!-- <view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('type')">
					<view class="text-333 text-df _left">马具类型</view>
					<view class="_right">
						<text class="text-df text-333">{{ saddleryType ? saddleryType : '请选择' }}</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view> -->
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
					@click="openPicker('selector')">
					<view class="text-333 text-df _left">品牌</view>
					<view class="_right">
						<text class="text-df text-333">{{ brandVal.name ? brandVal.name : '请选择' }}</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
					<view class="text-333 text-df _left">产地</view>
					<view class="_right">
						<view class="text-right _right"><input type="text" placeholder="请输入产地"
								placeholder-class="placeholder" v-model="goods_info.producing_area" /></view>
					</view>
				</view>
				<!-- <view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
					<view class="text-333 text-df _left">规格描述</view>
					<view class="_right">
						<view class="text-right _right"><input type="text" placeholder="请输入规格描述"
								placeholder-class="placeholder" v-model="goods_info.item" /></view>
					</view>
				</view> -->
				<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
					<view class="text-333 text-df _left">适用对象</view>
					<view class="_right">
						<view class="text-right _right"><input type="text" placeholder="请输入适用对象"
								placeholder-class="placeholder" v-model="goods_info.suit" /></view>
					</view>
				</view>

			</view>
			<view class="addGoods-item solid-bottom padding-bottom">
				<view class="text-333 text-df">描述</view>
				<view class="addGoods-content">
				<!-- {{goods_info.describe}} {{goods_info.description}}  :value="goods_info.describe"-->
					<textarea placeholder="请输入适用对象" v-model="goods_info.describe"></textarea>
				</view>
				<!-- <view class="addGoods-content"><fu-editor ref="editor" :htmlInfo="goods_info.body"></fu-editor></view> -->
			</view>
			<view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
				<view class="text-333 text-df">是否上架</view>
				<view class="">
					<switch class="switch" :color="goods_info.is_sale ? '#18BB3B' : ''" @change="handleSwitch"
						:checked="goods_info.is_sale ? true : false"></switch>
				</view>
			</view>
			<view class="addGoods-item  padding-tb flex justify-between align-center"
				:class="[goods_info.is_spec?'':'solid-bottom']">
				<view class="text-333 text-df">规格信息</view>
				<view class="">
					<switch class="switch" :color="goods_info.is_spec ? '#18BB3B' : ''" @change="specSwitch"
						:checked="goods_info.is_spec ? true : false"></switch>
				</view>
			</view>
			<block v-if="goods_info.is_spec">
				<view class="spec-box padding-tb-sm flex justify-between align-center">
					<view class="text-333 text-df _left">规格选择</view>
					<view class="_right text-999">
						<text class="text-df text-999" v-if="isHaveSpec" @click="openPicker('selector3')">
							<text v-if="specVal.name" @click.stop="goAddSpec(specVal.id)"
								class="text-blue margin-right-xs">编辑规格</text>
							<text>{{ specVal.name ? specVal.name : '请选择' }}</text>
						</text>
						<text v-else @click="goAddSpec(0)">
							该商品分类暂无规格
							<text class="text-blue margin-left-xs">去添加</text>
						</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				<view class="spec-box padding-tb flex justify-between align-center">
					<view class="text-333 text-df">规格详情</view>
					<view class="text-999" @click="handlerSpecInfo">
						<text>价格、库存</text>
						<text class="cuIcon-right text-999 margin-left-sm"></text>
					</view>
				</view>
				<view class="addGoods-item solid-bottom padding-tb" style="display:none">
					<!-- combinationSpecList -->
					<view class="addGoods-title text-333 text-lg ">规格列表</view>

					<view class="addGoods-content" v-for="(item, index) in combinationSpecList" :key="index">
						<view class="padding-tb-sm text-center">{{ item.item }}</view>
						<view class="flex justify-between align-center padding-tb-sm"
							v-for="(oItem, oIndex) in item.sku_name" :key="oIndex">
							<view class="text-999 text-df _left">{{ oItem.key }}</view>
							<view class="_right">
								<text class="text-df text-999">{{ oItem.name }}</text>
								<!-- <text class="cuIcon-right text-999 margin-left-sm"></text> -->
							</view>
						</view>

						<!-- 	<view class="flex justify-between align-center padding-tb-sm">
										<view class="text-999 text-df _left">划线价</view>
										<view class="text-right _right"><input v-model="item.market_price" type="number" placeholder="请输入" placeholder-class="placeholder" /></view>
									</view> -->
						<view class="flex justify-between align-center padding-tb-sm">
							<view class="text-999 text-df _left">价格</view>
							<view class="text-right _right"><input v-model="item.shop_price" type="number"
									placeholder="请输入" placeholder-class="placeholder" /></view>
						</view>
						<!-- 	<view class="flex justify-between align-center padding-tb-sm">
										<view class="text-999 text-df _left">会员价</view>
										<view class="text-right _right"><input v-model="item.member_price" type="number" placeholder="请输入" placeholder-class="placeholder" /></view>
									</view> -->
						<view class="flex justify-between align-center padding-tb-sm">
							<view class="text-999 text-df _left">进价</view>
							<view class="text-right _right"><input v-model="item.cost_price" type="number"
									placeholder="请输入" placeholder-class="placeholder" /></view>
						</view>
						<view class="flex justify-between align-center padding-tb-sm">
							<view class="text-999 text-df _left">库存</view>
							<view class="text-right _right">
								<input v-model="item.stock" type="number" placeholder="请输入"
									placeholder-class="placeholder" />
							</view>
						</view>
						<view class="flex justify-between align-center padding-tb-sm">
							<view class="text-999 text-df _left">库存预警</view>
							<view class="text-right _right"><input v-model="item.stock_warning" type="number"
									placeholder="请输入" placeholder-class="placeholder" /></view>
						</view>
					</view>
					<!-- <view class="btn-wrap flex justify-center align-center margin-top-16">
			  <view class="btn cancel margin-right-xs">删除</view>
			  <view class="btn margin-left-xs">确认</view>
			</view> -->
				</view>
			</block>
			<!-- <view class="addGoods-item solid-bottom padding-tb flex justify-between align-center">
				<view class="text-333 text-df _left">库存预警</view>
				<view class="text-right _right"><input type="number" placeholder="请输入商品库存预警" placeholder-class="placeholder" v-model="goods_info.stock_warning" /></view>
			</view> -->
			<!-- <view class="addGoods-item solid-bottom padding-tb flex justify-between align-center"
				@click="openPicker('selector2')">
				<view class="text-333 text-df _left">运费模板</view>
				<view class="_right">
					<text class="text-df text-333">{{ freightVal.name ? freightVal.name : '请选择' }}</text>
					<text class="cuIcon-right text-999 margin-left-sm" style="margin-top: 4rpx;"></text>
				</view>
			</view> -->
			<view class="submit-btn" @click="sureSubmit">{{goods_id?'确认修改':'确认发布'}}</view>
		</view>
		<!-- 商品分类 -->
		<w-picker :visible.sync="visible" mode="selector" :value="shopValue" :options="shopData" :level="1"
			default-type="name" :default-props="defaultProps" @confirm="onConfirm($event, 'shopCate')" @cancel="onCancel"
			ref="shopCate" themeColor='#FC6497'></w-picker>
		<!-- <w-picker :visible.sync="visible" mode="selector" :value="categoryValData" :options="categoryList" :level="1"
			default-type="id" :default-props="defaultProps1" @confirm="onConfirm($event, 'linkage')" @cancel="onCancel"
			ref="linkage" themeColor='#FC6497'></w-picker> -->
		<!-- 店铺内商品分类 -->
		<!-- <w-picker :visible.sync="visible" mode="linkage" :value="shopCategoryValData" :options="shopCategoryList"
			:level="3" default-type="id" :default-props="defaultProps1" @confirm="onConfirm($event, 'linkage2')"
			@cancel="onCancel" ref="linkage2" themeColor='#FC6497'></w-picker> -->
		<!-- 商品品牌 -->
		<w-picker :visible.sync="visible" mode="selector" :value="brandVal.name" default-type="name"
			:default-props="defaultProps" :options="brandList" @confirm="onConfirm($event, 'selector')"
			@cancel="onCancel" ref="selector" :level="1" themeColor='#FC6497'></w-picker>
		<!-- 年龄 :options="brandList" default-type="name" :default-props="defaultProps"  :options="[{name: 1, id: '1'}, {name: 1, id: '1'}, {name: 1, id: '1'}, {name: 1, id: '1'}, 5, 6, 7, 8, 9 , 10, 11, 12]-->
		<w-picker :visible.sync="visible" mode="date" :value="dateTime"
			 @confirm="onConfirm($event, 'date')"
			@cancel="onCancel" ref="time" :level="1" themeColor='#FC6497'></w-picker>
		<!-- <w-picker :visible.sync="visible" mode="date" :value="dateTime" 
			 @confirm="onConfirm($event, 'date')"
			@cancel="onCancel" ref="time" :level="1" themeColor='#FC6497' fields="day"></w-picker> -->
		<!-- 规格数据 -->
		<w-picker :visible.sync="visible" mode="selector" :value="specVal.name" default-type="name"
			:default-props="defaultProps" :options="specList" @confirm="onConfirm($event, 'selector3')"
			@cancel="onCancel" ref="selector3" themeColor='#FC6497'></w-picker>
		<!-- 运费模板 -->
		<w-picker :visible.sync="visible" mode="selector" :value="freightVal.name" default-type="name"
			:default-props="defaultProps" :options="freightList" @confirm="onConfirm($event, 'selector2')"
			@cancel="onCancel" ref="selector2" themeColor='#FC6497'></w-picker>
		<!-- 马匹规格 -->
		<!-- typesVal -->
		<w-picker :visible.sync="visible" mode="selector" :value="typesVal" default-type="name"
			:default-props="defaultProps" :options="typeData" @confirm="onConfirm($event, 'types')"
			@cancel="onCancel" ref="types" themeColor='#FC6497'></w-picker>
		<!-- 颜色 -->
		<w-picker :visible.sync="visible" mode="selector" :value="colorVal.name" :level="1" default-type="name"
			:default-props="defaultProps" :options="colorData" @confirm="onConfirm($event, 'color')" @cancel="onCancel"
			ref="color" themeColor='#FC6497'></w-picker>
		<!-- 用途 -->
		<w-picker :visible.sync="visible" mode="selector" :value="purposeVal" :level="1" default-type="name"
			:default-props="defaultProps" :options="purposeData" @confirm="onConfirm($event, 'purpose')"
			@cancel="onCancel" ref="purpose" themeColor='#FC6497'></w-picker>
		<!-- 用途 -->
		<w-picker :visible.sync="visible" mode="selector" :value="sexVal.name" :level="1" default-type="name"
			:default-props="defaultProps" :options="sexData" @confirm="onConfirm($event, 'sex')" @cancel="onCancel"
			ref="sex" themeColor='#FC6497'></w-picker>
	</view>
	
</template>

<script>
	// @see 引入验证，上传图片
	import {
		UploadImage
	} from '@/common/utils/index';
	import {
		UPLOAD_VIDEO_URL
	} from '@/common/config.js';
	import wPicker from "../../../user/components/w-picker/w-picker.vue";
	export default {
		components:{
			wPicker
		},
		data() {
			return {
				goods_info: {
					name: '', //标题
					thumb: '', //主图id
					video: '', //视频
					images: '', //商品轮播图
					body: '', //商品详情
					cid: '', //商品分类id
					goods_shop_category: '', //店铺分类id
					brand_id: '', //品牌id
					is_sale: true, //是否上架 1上架0下架
					market_price: '', //划线价，市场价
					shop_price: '', //本店价
					member_price: '', //会员价
					cost_price: '', //成本价
					freight_template_id: '', //运费模板id
					is_spec: false, //商品规格
					stock: '', //商品库存
					stock_warning: '', //商品库存预警
					spectypeid: '', //选中的规格名称id
					classify: '',
					video_img: '',
					video_picture: '',
					colour: "",
					used: "",
					sex: "",
					types: "",
					describe: ''
				},
				thumb_img: '',
				thumb_img_id:'',
				img_list: [], //轮播图
				body_list: [], //详情图片
				content: '', //详情内容
				max: 9, //轮播图做多上传多上张
				max_body: 12, //详情最多上传多少张图片
				editorCtx: '',
				videoInfo: {
					file: '', //视频路径，
					fileId: '', //视频id
					videoPoster: '', //视频封面图
				},
				categoryList: [], //商品分类数据
				shopCategoryList: [], //店铺内商品分类
				brandList: [], //商品品牌列表
				freightList: [], //运费模板
				defaultProps1: {
					label: 'name',
					value: 'id',
					children: 'child'
				},
				defaultProps: {
					label: 'name',
					value: 'id'
				},
				visible: false,
				defaultRegion1: [],
				categoryVal: {}, //商品分类选中数据
				saddleryType: '', // 马具类型
				categoryValData: [], //插件选择到指定位置
				shopCategoryVal: {}, //店铺内商品分类选中数据
				shopCategoryValData: [], //插件选择到指定位置
				brandVal: {}, //品牌选中数据
				dateTime: '', //年龄数据
				freightVal: {}, //运费数据
				goods_id: '', //商品id
				isHaveSpec: true, //判断是否有规格值
				specList: [], //规格数据
				specVal: {}, //所选规格数据
				combinationSpecList: [], //规格组合数据
				// radioColor: '#18BB3B',
				is_check: false,
				colorData: [],
				colorVal: "",
				typeData: [],
				typesVal: "",
				purposeData: [],
				purposeVal: "",
				sexData: [],
				sexVal: "",
				shopData:[],  // 商品分类数据
				shopValue:"", // 商品分类
				cartShow:false
			};
		},
		onLoad(options) {
			let {
				id
			} = options;
			this.goods_id = id;
			this.init(id);
			// 获取数据
			this.goods_type = uni.getStorageSync("USER_INFO").main_industry;
			this.goods_info.classify = this.goods_type
			console.log(this.goods_type)
			// let type = 0;
			// if(store_level==1){
			// 	type = 3
			// }
			// if(store_level==2){
			// 	type = 20
			// }
			// if(store_level==3){
			// 	type = 21
			// }
		},
		onShow() {
			let addSpecData = uni.getStorageSync('addSpec');
			if (addSpecData && this.goods_info.cid) {
				this.goods_info.spectypeid = addSpecData;
				this.getSpecData(this.goods_info.cid, addSpecData, false, true);
				uni.removeStorageSync('addSpec');
			}
			// uni.$on('addSpec', data => {
			// 	console.log('触发了addSpec', data);
			// 	if (this.goods_info.cid) {
			// 		this.goods_info.spectypeid = data;
			// 		this.getSpecData(this.goods_info.cid, data,false,true);
			// 	}
			// });
			let combinationSpecList = uni.getStorageSync('combinationSpecList');
			if (combinationSpecList) {
				this.combinationSpecList = JSON.parse(combinationSpecList);
				uni.removeStorageSync('combinationSpecList');
			}
			// uni.$on('combinationSpecList', data => {
			// 	console.log('触发了combinationSpecList', JSON.parse(data));
			// 	this.combinationSpecList = JSON.parse(data);
			// });

			// this.getDataCat()

		},
		onUnload() {
			// uni.$off('addSpec');
			// uni.$off('combinationSpecList');

		},
		methods: {
			openPickerss(){
				console.log(this.cartShow)
				this.cartShow = true
				// console.log( this.$refs)
				// this.$refs['shopCate'].show();
			},
			handleAge() {
				
			},
			async init(id) {
				console.log(id)
				if(id){
					this.getGoodsInfo(id)
				}
				this.postGoodsGetCategoryList();
				this.get_shop_category();
				this.postBrandShow();
				this.goods_freight();
			},
			// 去添加规格
			goAddSpec(id) {
				// if (!this.goods_info.cid) return this.$message.info('请先选择商品分类');
				// 判断该商品规格是否可进行编辑
				new Promise((resolve, reject) => {
					this.$api
						.post(global.apiUrls.addSpec, {
							id: id
						})
						.then(res => {
							console.log(res);
							if (res.data.code == 1) {
								resolve(true);
							} else {
								this.$message.info(res.data.msg);
								resolve(false);
							}
						})
						.catch(err => {
							console.log(err);
							reject(err);
						});
				}).then(res => {
					console.log(res);
					if (res) {
						uni.navigateTo({
							url: '/pages/tab/management/addSpec/index?cid=' + this.goods_info.cid +
								'&id=' + id
						});
					}
				});

				// this.$message.info('正在开发中，请先从pc端添加');
			},
			handlerSpecInfo() {
				if (!this.specVal.id) return this.$message.info('请先选择规格');
				uni.setStorageSync('combinationSpecList', JSON.stringify(this.combinationSpecList));
				uni.navigateTo({
					url: '/pages/tab/management/specInfo/index'
				});
			},
			// 编辑时获取详情
			getGoodsInfo(id) {
				this.$api
					.get(global.apiUrls.goods_info, {
						goods_id: id,
						partner_id: this.$store.state.userInfo.id
					})
					.then(res => {
						console.log(res, '999');
						if (res.data.code == 1) {
							let data = res.data.data.goods;
							console.log(data.thumb_url)
							this.goods_info = {
								name: data.name, //标题
								thumb: data.thumb, //主图id
								video: data.video, //视频
								images: data.images, //商品轮播图
								video_img: data.video_img,
								body: data.body, //商品详情
								cid: data.cid, //商品分类id
								goods_shop_category: data.goods_shop_category, //店铺分类id
								brand_id: data.brand_id, //品牌id
								is_sale: data.is_sale == 1 ? true : false, //是否上架 1上架0下架
								market_price: data.market_price, //划线价，市场价
								shop_price: data.shop_price, //本店价
								member_price: data.member_price, //会员价
								cost_price: data.cost_price, //成本价
								freight_template_id: data.freight_template_id, //运费模板id
								is_spec: data.is_spec == 1 ? true : false, //商品规格
								stock: data.stock, //商品库存
								stock_warning: data.stock_warning, //商品库存预警
								spectypeid: data.spectypeid, //选中规格名称的id
								sex: data.sex,
								types: data.types,
								used: data.used,
								colour: data.colour,
								birthday: data.birthday,
								age: data.age,
								height: data.height,
								weight_body: data.weight_body,
								adslogan: data.adslogan,
								producing_area: data.producing_area,
								suit: data.suit,
								describe: data.describe,
								// types: data.types,
								classify: data.classify,
								
							};
							console.log(data.types, '、i她她她')
							console.log(data.thumb_url)
							this.thumb_img = data.thumb_url;
							this.thumb_img_id = data.thumb
							// this.typesVal = data.types
							// this.sexVal= data.sex;
							// this.purposeVal = data.used ;
							// this.colorVal.name =  data.colour;
							// this.dateTime = data.birthday;
							// this.color = data.colour;
							console.log(data.types)
							console.log(data.sex)
							console.log(data.used)
							console.log(this.colour)
							// this.$message.info(this.goods_info.body)
							if (data.is_spec) {
								this.getSpecData(data.cid, data.spectypeid, data.goods_spec.items);
							}
							this.postBrandShow(data.cid);
							//       this.$nextTick(() => {
							//         this.$refs.editor.setHtml(this.goods_info.body);
							// });
							// 增加延时赋值 解决获取不到富文本就赋值的情况
							// setTimeout(() => {
							// 	this.$refs.editor.setHtml(this.goods_info.body);
							// }, 500);
							console.log(this.thumb_img)
							this.videoInfo = {
								file: data.video_url,
								fileId: data.video,
								videoPoster: data.video_img
							};
							let images_arr = data.images.split(',');
							let img_list = [];
							images_arr.forEach((val, i) => {
								img_list.push({
									id: val,
									path: data.images_url[i]
								});
							});
							this.img_list = img_list;
							this.categoryVal = {
								id: data.cid,
								name: data.category_name
							};
							this.shopCategoryVal = {
								id: data.goods_shop_category,
								name: data.shop_category_name
							};
							this.brandVal = {
								id: data.brand_id,
								name: data.brand_name
							};
							this.freightVal = {
								id: data.freight_template_id,
								name: data.freight_template_name
							};
						} else {
							this.$message.info(res.data.msg);
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			// 预览
			previewGoods() {
				let {
					name,
					shop_price
				} = this.goods_info;
				console.log(this.goods_info, '555');
				console.log(name, shop_price);
				if (!name || this.img_list.length == 0 || !shop_price) {
					this.$message.info('请确认标题、轮播图、商品本店价是否填写');
					return;
				}
				// this.$refs.editor.getContent().then(res => {
				let data = {
					img_list: this.img_list,
					videoInfo: this.videoInfo,
					name: this.goods_info.name,
					shop_price: this.goods_info.shop_price,
					// body: res.html
					// describe:this.goods_info.describe
				};
				data = JSON.stringify(data);
				uni.setStorageSync('CONTENT', data);
				uni.navigateTo({
					url: '/pages/tab/management/goodsPreview/index'
				});
				// });
			},
			// 提交
			sureSubmit() {
				let images = [];
				// this.$refs.editor.getContent().then(res => {
				// let html = res.html;

				// if (html != '<p><br></p>') html = html.substring(3, html.length - 4);
				// console.log(html.substring(3, html.length - 4));
				let html = this.goods_info.describe
				this.goods_info.body = html;
				this.goods_info.thumb = this.thumb_img_id
				this.goods_info.is_sale = this.goods_info.is_sale ? 1 : 0;
				this.goods_info.is_spec = this.goods_info.is_spec ? 1 : 0;
				this.goods_info.goods_type = this.goods_info.goods_type
				// this.goods_info.d
				this.img_list.forEach(val => {
					images.push(val.id);
				});
				this.goods_info.images = images.join(',');
				if (this.checkGoodsInfo()) {
					this.$message.info(this.checkGoodsInfo());
					return;
				}
				if (!this.goods_info.spectypeid && this.goods_info.is_spec) return this.$message.info(
					'规格id丢失');
				if (this.goods_info.is_spec) {
					let obj = {};
					this.combinationSpecList.forEach(val => {
						obj[val.id] = val;
					});

					this.goods_info.item = JSON.stringify(this.combinationSpecList);
					console.log(this.goods_info.item, 'this.goods_info.ite')
				}
				console.log('查看数据', this.goods_info);
				if (this.goods_id) {
					this.goods_edit(this.goods_info);
				} else {
					this.goods_add(this.goods_info);
				}
				// });
			},
			goods_edit(data) {
				let _this = this
				if (this.is_check) return
				this.is_check = true
				data.id = this.goods_id;
				data.partner_id = this.$store.state.userInfo.id;
				data.age = data.birthday
				this.$api
					.post(global.apiUrls.goods_edit, data)
					.then(res => {
						console.log(res);
						if (res.data.code == 1) {
							this.$message.info('提交成功');
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								});
								_this.is_check = false
							}, 800);
						} else {
							this.$message.info(res.data.msg);
							this.is_check = false
						}
						this.is_check = false
					})
					.catch(err => {
						console.log(err);
					});
			},
			goods_add(data) {
				console.log(data)
				let _this = this
				if (this.is_check) return
				this.is_check = true
				this.$api
					.post(global.apiUrls.goods_add, data)
					.then(res => {
						console.log(res);
						if (res.data.code == 1) {
							this.$message.info('提交成功');
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								});
								_this.is_check = false
							}, 800);
						} else {
							this.$message.info(res.data.msg);
							this.is_check = false
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			// 验证
			checkGoodsInfo() {
				let str = '';
				if (!this.goods_info.name.trim()) {
					str = '请输入商品名称';
					return str;
				}
				// this.goods_info.thumb = this.goods_info.images[0]
				// console.log(this.goods_info.thumb, 'iooo')
				// if (!this.goods_info.thumb.trim()) {
				// 	str = '请上传商品主图';
				// 	return str;
				// }
				if (!this.goods_info.images.trim()) {
					str = '请上传商品轮播图';
					return str;
				}
				// if (this.goods_info.body == '<p><br></p>' || !this.goods_info.body.trim()) {
				// 	str = '请填写商品详情';
				// 	// this.$message.info('请填写商品详情');
				// 	return str;
				// }
				// if (!this.goods_info.cid) {
				// 	str = '请选择商品分类';
				// 	return str;
				// }
				/* if (!this.goods_info.goods_shop_category) {
        str = '请选择店铺分类';
        return str;
      }
      if (!this.goods_info.brand_id) {
        str = '请选择品牌';
        return str;
      } */
				console.log(this.combinationSpecList);
				if (this.goods_info.is_spec) {
					let err = '';
					for (let i = 0; i < this.combinationSpecList.length; i++) {
						let val = this.combinationSpecList[i];
						let sku_name = this.combinationSpecList[i].item;
						// if (!val.market_price.trim()) {
						// 	err = '请输入' + sku_name + '商品划线价';
						// 	break;
						// } else {
						// 	if (val.market_price <= 0) {
						// 		err = sku_name + '商品划线价需要大于0';
						// 		break;
						// 	}
						// }
						if (!val.shop_price.trim()) {
							err = '请输入' + sku_name + '商品本店价';
							break;
						} else {
							if (val.shop_price <= 0) {
								err = sku_name + '商品本店价需要大于0';
								break;
							}
						}
						// if (!val.member_price.trim()) {
						// 	err = '请输入' + sku_name + '商品会员价';
						// 	break;
						// } else {
						// 	if (val.member_price <= 0) {
						// 		err = sku_name + '商品会员价需要大于0';
						// 		break;
						// 	}
						// }
						if (!val.cost_price.trim()) {
							err = '请输入' + sku_name + '商品成本价';
							break;
						} else {
							if (val.cost_price <= 0) {
								err = sku_name + '商品成本价需要大于0';
								break;
							}
						}

						if (!val.stock) {
							err = '请输入' + sku_name + '商品库存';
							break;
						} else {
							if (val.stock <= 0) {
								err = sku_name + '商品库存需要大于0';
								break;
							}
						}

						// if (!val.stock_warning) {
						// 	err = '请输入' + sku_name + '商品库存';
						// 	break;
						// } else {
						// 	if (val.stock_warning <= 0) {
						// 		err = sku_name + '商品库存预警需要大于0';
						// 		break;
						// 	}
						// }

					}
					if (err) return err;
				}
				// if (!this.goods_info.market_price.trim()) {
				// 	str = '请输入商品划线价';
				// 	return str;
				// } else {
				// 	if (this.goods_info.market_price <= 0) {
				// 		str = '商品划线价需要大于0';
				// 		return str;
				// 	}
				// }
				if (!this.goods_info.shop_price.trim()) {
					str = '请输入商品本店价';
					return str;
				} else {
					if (this.goods_info.shop_price <= 0) {
						str = '商品本店价需要大于0';
						return str;
					}
				}
				// if (!this.goods_info.member_price.trim()) {
				// 	str = '请输入商品会员价';
				// 	return str;
				// } else {
				// 	if (this.goods_info.member_price <= 0) {
				// 		str = '商品会员价需要大于0';
				// 		return str;
				// 	}
				// }
				if (!this.goods_info.cost_price.trim()) {
					str = '请输入商品成本价';
					return str;
				} else {
					if (this.goods_info.cost_price <= 0) {
						str = '商品成本价需要大于0';
						return str;
					}
				}

				if (!this.goods_info.stock) {
					str = '请输入商品库存';
					return str;
				} else {
					if (this.goods_info.stock <= 0) {
						str = '商品库存需要大于0';
						return str;
					}
				}

			},
			/**
			 * @func 切换是否上架
			 */
			handleSwitch(e) {
				this.goods_info.is_sale = e.detail.value;
			},
			/**
			 * @func 切换是否上架
			 */
			specSwitch(e) {
				this.goods_info.is_spec = e.detail.value;
				if (e.detail.value) {
					this.getSpecData(this.goods_info.cid, false, false);
				}
			},
			/**
			 * @param num 一次最多上传几张
			 * @param type thumb 主题  img_list 轮播图  body_list 商品详情图片
			 * @param max 最多上传多上张图片
			 */
			upLoadImg(num, type, max = 1) {
				let n = 1;
				if (type != 'thumb') {
					num = num > max ? max : num;
					// 剩余可上传数量
					let surplus = max - this[type].length;
					if (num > surplus) {
						n = surplus;
					} else {
						n = num;
					}
				}
				uni.chooseImage({
					count: n,
					sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera', 'album'], // 可以指定来源是相册还是相机，默认二者都有
					success: res => {
						console.log(res);
						let list = res.tempFilePaths;
						list.forEach((val, i) => {
							this.uploadUserImg(val, type, list, i);
						});
					}
				});
			},
			/**
			 * @description 上传图片
			 */
			uploadUserImg(blob, type, list, i) {
				// uni.showLoading();
				let _this = this;
				// 开始上传
				new UploadImage([blob], {
					complete: function(res) {
						console.log(res);
						if (res.length) {
							if (type == 'thumb') {
								_this.thumb_img = res[0].path;
								_this.thumb_img_id = res[0].id
								// _this.goods_info.thumb = res[0].id;
								console.log(_this.thumb_img, res[0].thumb);
							}
							if (type == 'img_list') {
								_this.img_list.push(res[0]);
							}
							if (type == 'body_list') {
								_this.body_list.push(res[0]);
							}
						}
					}
				});
			},
			clearImg(type, id) {
				if (type == 'thumb') {
					this.thumb_img = '';
					this.goods_info.thumb = '';
				}
				if (type == 'img_list') {
					let index = this.img_list.findIndex(item => item.id == id);
					this.img_list.splice(index, 1);
				}
				if (type == 'body_list') {
					let index = this.body_list.findIndex(item => item.id == id);
					this.body_list.splice(index, 1);
				}
			},
			// 上传视频
			addVideo(data) {
				uni.chooseVideo({
					maxDuration: 60,
					count: 1,
					sourceType: ['album', 'camera'],
					success: responent => {
						console.log(responent);
						uni.showLoading({
							title: '上传中...'
						});
						// this.isUpl = true
						let videoFile = responent.tempFilePath;
						let size = Math.ceil(responent.size / 1024 / 1024);
						console.log(size);
						if (size > 50) {
							uni.hideLoading();
							return this.$message.info('视频大小不能超过50M');
						}
						let that = this
						const uploadTask = uni.uploadFile({
							url: UPLOAD_VIDEO_URL,
							filePath: videoFile,
							name: 'file',
							success: res => {
								uni.hideLoading();
								console.log(res);
								let videoUrls = JSON.parse(res.data); //微信和头条支持
								console.log(11111, videoUrls);
								if (videoUrls.code == 1) {
									var fileData = videoUrls.data;
									// img_url
									fileData.videoPoster = fileData.data.path;
									that.videoInfo = fileData.data;
									that.goods_info.video = fileData.data.fileId;
									that.goods_info.video_img = fileData.data.img_url
									that.goods_info.video_picture = fileData.data.img_url
									//img_url;
									// videoInfo: {
									// 	file: '', //视频路径，
									// 	fileId: '', //视频id
									// 	videoPoster: '' ,//视频封面图
									// },
								}
							},
							fail: () => {
								uni.hideLoading();
								// this.isUpl = false
							}
						});
						uploadTask.onProgressUpdate(res => {
							//   this.videoList.loading = res.progress + "%";
							//   console.log(this.videoList.loading)
						});
					}
				});
			},
			clearVideo() {
				this.videoInfo = {};
				this.goods_info.video = '';
			},
			// 获取商品分类
			postGoodsGetCategoryList() {
				// this.$api
				// 	.post(global.apiUrls.postGoodsGetCategoryList, {
				// 		partner_id: this.$store.state.userInfo.id
				// 	})
				this.$api
					.post(global.apiUrls.postGoodsGetCategoryList, {
						// partner_id: this.$store.state.userInfo.id
						pid:0
					})
					.then(res => {
						console.log('商品分类', res);
						if (res.data.code == 1) {
							let list = res.data.data;
							console.log(list)
							this.shopData = list
							// 判断没有二级分类删除此分类
							// list.forEach((item, index) => {
							// 	// if (!item.child) {
							// 	// 	list.splice(index, 1);
							// 	// } else {
							// 	// 	// 二级没有三级child删除
							// 	// 	item.child.forEach((val, i) => {
							// 	// 		if (!val.child) {
							// 	// 			item.child.splice(i, 1);
							// 	// 		}
							// 	// 	});
							// 	// }

							// 	// // 判断没有三级分类删除此分类
							// 	// if (this.filterEmpty(item.child)) {
							// 	// 	list.splice(index, 1);
							// 	// }
							// });

							// this.categoryList = list;
							// this.categoryValData = this.getCidList(this.categoryList, this.goods_info.cid);
							// console.log(list, "***********")
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			// 获取店铺内商品分类
			get_shop_category() {
				this.$api
					.post(global.apiUrls.get_category_list, {
						partner_id: this.$store.state.userInfo.id
					})
					.then(res => {
						if (res.data.code == 1) {

							let list = res.data.data;
							// 判断没有二级分类删除此分类
							list.forEach((item, index) => {
								if (!item.child) {
									list.splice(index, 1);
								} else {
									// 二级没有三级child删除
									item.child.forEach((val, i) => {
										if (!val.child) {
											item.child.splice(i, 1);
										}
									});
								}

								// 判断没有三级分类删除此分类
								if (this.filterEmpty(item.child)) {
									list.splice(index, 1);
								}
							});
							this.shopCategoryList = list;
							this.shopCategoryValData = this.getCidList(list, this.goods_info.goods_shop_category);

						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			// 获取品牌列表
			postBrandShow(cid) {
				this.brandList = []
				this.brandVal = {}
				this.$api
					.post(global.apiUrls.shopBrand, {
						cid: cid
					})
					.then(res => {
						// console.log(res);
						if (res.data.code == 1) {
							this.brandList = res.data.data;
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			// 获取选项

			getDataCat() {

				this.$api
					.post(global.apiUrls.getDataCat)
					.then(res => {
						// console.log(res);
						if (res.data.code == 1) {
							let dataCat = res.data.data;
							
							// 添加类型
							let typeData = []
							dataCat.types.forEach(v => {
							
								typeData.push({
									"id": v,
									"name": v
								});
							});
							this.typeData = typeData;
							console.log(this.typeData, 'this.typeData')
							let colorData = []
							dataCat.color.forEach(v => {

								colorData.push({
									"id": v,
									"name": v
								});
							});
							this.colorData = colorData;

							let purposeData = []
							dataCat.purpose.forEach(v => {

								purposeData.push({
									"id": v,
									"name": v
								});
							});
							this.purposeData = purposeData;

							let sexData = []
							dataCat.sex.forEach(v => {

								sexData.push({
									"id": v,
									"name": v
								});
							});
							this.sexData = sexData;


						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			/**
			 * @description 根据分类id查找规格数据
			 * @param {String} cid商品分类id spectypeid规格id goods_spec规格数据 isEmit是否是添加规格推送
			 */
			getSpecData(cid, spectypeid, goods_spec, isEmit = false) {
				console.log('规格id>>>>>', cid, spectypeid, goods_spec, isEmit);
				this.$api
					.post(global.apiUrls.getSpecByCid, {
						cid: cid
					})
					.then(res => {
						console.log('规格>>>>>', res);
						if (res.data.code == 1) {
							if (res.data.data.length == 0) {
								this.isHaveSpec = false;
								return;
							}
							this.isHaveSpec = true;
							let list = res.data.data;
							list.push({
								id: 0,
								name: '添加新规格'
							});
							this.specList = list;

							if (spectypeid) {
								this.specVal = list.find(item => item.id == spectypeid);
								if (goods_spec) this.editSkuName(goods_spec, this.specVal);
								if (isEmit) {
									let skuList = []; //把各个规格属性整合成一个二维数组
									// 先把规格属性写入每个规格上，以便后续取用
									let list1 = this.specList.find(item => item.id == spectypeid);
									console.log('7987987987989', list1)
									if (list1.spec) {
										list1.spec.forEach(v => {
											v.spec_item.forEach(b => {
												b.sku_name = v.name;
											});
											skuList.push(v.spec_item);
										});
										this.combinationSpecList = this.getSkuName(skuList, list1);
									}

								}
							}
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			// 规格排列组合
			specFun(list) {
				let cloneList = JSON.parse(JSON.stringify(list));

				console.log(cloneList, 'xiangyuan')
				if (cloneList.length <= 1) {
					return cloneList[0];
				}
				let arr = [];
				cloneList[0].forEach(a => {
					cloneList[1].forEach(b => {
						let obj2 = {
							item: a.item + '-' + b.item,
							id: a.id + '_' + b.id
						};
						arr.push(obj2);
					});
				});
				cloneList.splice(0, 2);
				cloneList.unshift(arr);
				if (cloneList.length >= 1) {
					return this.specFun(cloneList);
				}
			},
			// 获取运费模板

			goods_freight() {
				this.$api
					.get(global.apiUrls.goods_freight, {
						partner_id: this.$store.state.userInfo.id
					})
					.then(res => {
						console.log(res);
						if (res.data.code == 1) {
							this.freightList = res.data.data;
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			/**
			 * @description 判断是否有子分类
			 */
			filterEmpty(arr) {
				if (!arr) {
					return false;
				}
				let num = 0;
				arr.forEach(item => {
					if (!item.child) {
						num++;
					}
				});
				if (num == arr.length) {
					return true;
				} else {
					return false;
				}
			},
			// 打开弹窗
			openPicker(type) {
				if (type == 'selector3' && !this.goods_info.cid) {
					this.$message.info('请先选择商品分类');
					return;
				}
				if (type == 'linkage') {
					if (this.categoryList.length == 0) {
						this.$message.info('商品分类为空');
						return;
					}
				}
				if(type == 'types') {
					
				}
				// if(type == 'linkage2'){
				//   if(this.shopCategoryList.length == 0){
				//     this.$message.info('店内商品分类为空');
				//   return;
				//   }
				// }
				this.$refs[type].show();
			},
			onConfirm(res, type) {
				console.log(res, type);
				if (res.obj) {
					if (type == 'linkage') {
						this.categoryVal = res.obj.col2;
						this.goods_info.cid = res.obj.col2.id;
						this.specVal = {};
						this.getSpecData(res.obj.col2.id, false, false);
						this.postBrandShow(res.obj.col2.id);
					}
					if (type == 'linkage2') {
						this.shopCategoryVal = res.obj.col2;
						this.goods_info.goods_shop_category = res.obj.col2.id;
					}
					if (type == 'selector') {
						this.brandVal = res.obj;
						this.goods_info.brand_id = res.obj.id;
					}
					if (type == 'selector2') {
						this.freightVal = res.obj;
						this.goods_info.freight_template_id = res.obj.id;
					}
					if (type == 'types') {
						this.typesVal = res.obj.name;
						this.goods_info.types = res.obj.name;
					}
					if(type == 'date') {
						// console.log(res, type);
						this.dateTime = res.value
						this.goods_info.birthday = res.value;
					}
					if (type == 'color') {
						this.colorVal = res.obj.name;
						this.goods_info.colour = res.obj.name;
					}
					if (type == 'purpose') {
						this.purposeVal = res.obj.name;
						this.goods_info.used = res.obj.name;
					}
					if (type == 'sex') {
						this.sexVal = res.obj.name;
						this.goods_info.sex = res.obj.name;
					}
					
					if(type == 'shopCate'){
						this.shopValue = res.obj.name;
						this.goods_info.cid = res.obj.id;
						this.specVal = {};
						this.getSpecData(res.obj.id, false, false);
						// this.postBrandShow(res.obj.id);
					}

					if (type == 'selector3') {
						if (res.obj.id == 0) {
							if (!this.goods_info.cid) return this.$message.info('请先选择商品分类');
							uni.navigateTo({
								url: '/pages/tab/management/addSpec/index?cid=' + this.goods_info.cid + '&id=0'
							});
							return;
							
						}
						this.specVal = res.obj;
						this.goods_info.spectypeid = res.obj.id;
						let skuList = []; //把各个规格属性整合成一个二维数组
						// 先把规格属性写入每个规格上，以便后续取用
						let list = this.specList.find(item => item.id == res.obj.id);
						list.spec.forEach(v => {
							v.spec_item.forEach(b => {
								b.sku_name = v.name;
							});
							skuList.push(v.spec_item);
						});
						this.combinationSpecList = this.getSkuName(skuList, list);
					}
				}

			},
			// 编辑时整合数据
			editSkuName(arr, list) {
				let newArr = [];
				// 转换数据格式
				for (let attr in arr) {
					let obj = arr[attr];
					obj.id = attr;
					newArr.push(obj);
				}

				newArr.forEach((val, i) => {
					val.item = val.key_name;
					let skuName = val.item.split('-');

					let sku_name_list = [];
					list.spec.forEach((b, bi) => {
						// console.log(b);
						let sku_obj = {
							key: b.name,
							name: skuName[bi]
						};
						sku_name_list.push(sku_obj);
						// console.log(sku_obj);
					});
					val.sku_name = sku_name_list;
				});
				this.combinationSpecList = newArr;
				console.log('编辑时规格得到的数据》》》》》》》》', newArr);
			},

			// inputChange(val) {
			// 	console.log(val)
			// 	console.log(value)
			// 	if(val==1) {
			// 		var price = this.goods_info.market_price.toString().replace(/(?<=\.[0-9]{2})\d+/, '')
			// 		this.$nextTick(() => {
			// 			this.goods_info.market_price = price
			// 		})
			// 	}

			// 	if(val==2){
			// 		var price1 = this.goods_info.shop_price.toString().replace(/(?<=\.[0-9]{2})\d+/, '')
			// 		this.$nextTick(() => {
			// 			this.goods_info.shop_price = price1
			// 		})
			// 	}

			// 	if(val==3){
			// 		var price2 = this.goods_info.cost_price.toString().replace(/(?<=\.[0-9]{2})\d+/, '')
			// 		this.$nextTick(() => {
			// 			this.goods_info.cost_price = price2
			// 		})
			// 	}
			// },

			// 整合数据
			getSkuName(skuList, list) {


				console.log(skuList, 'opoodddd')
				console.log(list, 'opooddddlist')
				let arr = this.specFun(skuList);

				console.log(arr, 'sssddddd')

				// return

				arr.forEach((val, i) => {
					val.cost_price = '';
					val.market_price = '';
					val.shop_price = '';
					val.member_price = '';
					val.stock = '';
					val.stock_warning = '';
					val.key_name = val.item;
					let skuName = val.item.split('-');
					let sku_name_list = [];
					list.spec.forEach((b, bi) => {
						// console.log(b);
						let sku_obj = {
							key: b.name,
							name: skuName[bi]
						};
						sku_name_list.push(sku_obj);
						// console.log(sku_obj);
					});
					val.sku_name = sku_name_list;
				});
				return arr;
			},
			onCancel() {},
			// 注释：数据结构不确定层级，不确定是否有子集（children） ，要求通过id获得指定数据的位置并记录他的层级内容信息
			// 获取指定id的位置   并以层级的形式放入数组
			//  要求获取指定层级的信息 如 id 1  结果 [1]  id 6 结果 [3,6]  id 11 结果 [1，5，8，11]
			getCidList(val, id) {
				let cid_list = [];
				val.forEach((item, index) => {
					if (item.id == id) {
						cid_list = [item.id];
						return false;
					} else {
						if (item.child) {
							let newCid_list = [item.id];
							let list = this.nodefun(item.child, id, newCid_list);
							if (list) {
								cid_list = list;
							}
						}
					}
				});
				return cid_list;
			},
			// 递归函数
			nodefun(newVal, newId, newCid_list) {
				let flag = false;
				newVal.forEach(j => {
					// console.log(j)
					if (j.id == newId) {
						newCid_list.push(j.id);
						flag = true;
					} else {
						if (j.child) {
							let cid_list = JSON.parse(JSON.stringify(newCid_list));
							cid_list.push(j.id);
							let list = this.nodefun(j.child, newId, cid_list);
							if (list) {
								newCid_list = list;
								flag = true;
							}
						}
					}
				});
				if (flag) {
					return newCid_list;
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	page {
		height: 100%;
		background: #ffffff;
	}
	input {
		font-size: 28rpx !important;
	}
	textarea {
		font-size: 28rpx !important;
	}
	.page {
		height: 100%;
		background: #ffffff;
	}

	.margin-top-16 {
		margin-top: 16rpx;
	}

	.placeholder {
		color: #999999;
		font-size: 28rpx;
	}

	.addGoods-item {
		margin: 0 32rpx;

		._left {
			flex-shrink: 0;
		}

		._right {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			text-align: right;
			width: calc(100% - 200rpx);

			text {
				&:first-child {
					width: calc(100% - 100rpx);
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}
			}

			input {
				width: calc(100% - 100rpx);
			}
		}

		.addGoods-content {
			.textarea-title {
				height: 140rpx;
				width: 100%;
			}

			.image-wrap::after {
				content: '';
				flex: auto;
			}

			.add-img {
				width: 218rpx;
				height: 218rpx;
				border-radius: 16rpx;
				margin-bottom: 16rpx;
			}

			.goods-img {
				width: 218rpx;
				height: 218rpx;
				border-radius: 16rpx;
				margin-bottom: 16rpx;
				position: relative;

				&:nth-of-type(3n + 2) {
					margin: 0 18rpx;
				}

				.img {
					width: 218rpx;
					height: 218rpx;
					border-radius: 16rpx;
				}

				.close {
					position: absolute;
					top: 12rpx;
					right: 12rpx;
					width: 32rpx;
					height: 32rpx;
					border-radius: 50%;
				}
			}

			.textarea-content {
				height: 140rpx;
				width: 100%;
			}
		}

		.btn-wrap {
			.btn {
				width: 200rpx;
				height: 72rpx;
				line-height: 72rpx;
				text-align: center;
				border: 1rpx solid #ff5001;
				border-radius: 36rpx;
				font-size: 28rpx;
				font-weight: 500;
				color: #ff5001;

				&.cancel {
					border: 1px solid #bfbfbf;
					color: #333333;
				}
			}
		}
	}

	.spec-box {
		background-color: #F8F8F8;
		padding: 32rpx;
	}

	.submit-btn {
		width: 686rpx;
		height: 90rpx;
		line-height: 90rpx;
		background: $bgtheme;
		border-radius: 45rpx;
		text-align: center;
		font-size: 32rpx;
		color: #ffffff;
		margin: 64rpx auto;
	}

	/deep/ .switch {
		transform: scale(0.7);
	}
</style>